Polygons


Problem 1
Create an Open GL application called GreenTriang to test triangles in Open GL.
Cree una aplicación de Open GL llamada GreenTriang para probar los triángulos en Open GL.

GreenTriangRun

GreenTriang.cpp
...
bool GreenTriang::RenderScene()
{
     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);// clear screen and depth buffer

     glLoadIdentity();
     gluLookAt(0.0f, 10.0f, 0.1f, //The position of the eye point
          0.0f, 0.0f, 0.0f, //The position of the reference point
          0.0f, 1.0f, 0.0f); //The direction of the up vector.

     glColor3f(0.0f, 1.0f, 0.0f);
     glBegin(GL_TRIANGLES);
          glVertex3f(-4.0f, -4.0f, 0.0f);
          glVertex3f(3.0f, -3.0f, 2.0f);
          glVertex3f(0.0f, 0.0f, 0.0f);
     glEnd();

     return true; // return false to stop
}


Problem 2
Create an Open GL application called PinkPolygon to test polygons in Open GL.
Cree una aplicación de Open GL llamada PinkPolygon para probar los polígonos en Open GL.

PinkPolygonRun1

PinkPolygonRun2

PinkPolygon.cpp
...
bool PinkPolygon::RenderScene()
{
     //____________________________________________________ Polygon
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// clear screen and depth buffer
     glLoadIdentity();
     gluLookAt(0.0, 10.0, 0.1, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
     static float angle = 0.0f;
     glPolygonMode(GL_FRONT, GL_LINE); // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
     glPushMatrix();
     glTranslatef(-4.0f, 0.0f, 0.0f);
     glRotatef(angle, 0.0f, 0.0f, 1.0f); //glRotatef(angle, 0.0f, 1.0f, 0.0f);
     glColor3f(1.0f, 0.5f, 0.5f);
     glBegin(GL_POLYGON);
     glVertex3f(-1.5f, 0.0f, 0.0f);
     glVertex3f(1.5f, 0.0f, 0.0f);
     glVertex3f(1.5f, 0.0f, -2.0f);
     glVertex3f(-1.5f, 0.0f,-2.0f);
     glEnd();
     glPopMatrix();
     angle += 2.0f;
     if (angle >= 360.0) angle -= 360.0;

     return true; // return false to stop
}


glPushMatrix and glPopMatrix

glPushMatrix stores the current matrix to preserve the state of the matriz. Usually, you should use glPushMatrix before calling glTranslate and glRotate. A call to glPopMatrix restores the matrix to its original state.
glPushMatrix almacena la matriz corriente para preservar el estado de la matriz. Usualmente, usted debe llamar glPushMatrix antes de llamar glTranslate y glRotate. Una llamada a glPopMatrix restablece la matriz a su estado previo..

Quad

A quad describes a surface of four points in a 3D space.
Un quad describe una superficie de cuatro puntos en un espacio 3D.

Problem 3
Create an Open GL application called RedQuad to test quads in Open GL.
Cree una aplicación de Open GL llamada RedQuad para probar los quads en Open GL.

RedQuadRun

RedQuad.cpp
...
bool RedQuad::RenderScene()
{
     //_______________________________________________ Quads
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// clear screen and depth buffer
     glLoadIdentity();
     gluLookAt(10.0f, 10.0f, 10.0f, 10.0f, 10.0f, 0.0f, 0.0f, 1.0f, 0.0f);
     glColor3f(1.0f, 0.0f, 0.0f);
     glPushMatrix();
          glTranslatef((GLfloat)(-80.0), (GLfloat)(-80.0), -250.0f);
          glBegin(GL_QUADS);
               glVertex3f(0.0f, 0.0f, 0.0f); // left bottom
               glVertex3f(0.0f, 50.0f, 0.0f); //left top
               glVertex3f(50.0f, 50.0f, 0.0f); //right top
               glVertex3f(150.0f, 0.0f, 0.0f); //right bottom
          glEnd();
     glPopMatrix();

     return true; // return false to stop
}


Triangle Strip

It is a collection of triangles to create a 3D surface. Most 3D object are drawn using triangles because there are efficient algorithms to draw triangles.
Es una colección de triángulos para crear una superficie 3D. La mayoría de los objetos en 3D usan triángulos porque existen algoritmos eficientes para dibujar triángulos.

Problem 4
Create an Open GL application called BoxCyan to test triangle strips in Open GL.
Cree una aplicación de Open GL llamada BoxCyan para probar las bandas de triángulos en Open GL.

BoxCyanRun

BoxCyan.cpp
...
bool BoxCyan::RenderScene()
{
     //_______________________________________________ Triangle Strip
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// clear screen and depth buffer
     glLoadIdentity();
     gluLookAt(0.0f, 10.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
     glPushMatrix();
          glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
          glTranslatef(-6.0f, 0.0f, 0.5f);

          for (int x = 0; x < 3; x++)
          {
               glBegin(GL_TRIANGLE_STRIP);
               //___________________________________________ Color
               if (x == 0) glColor3f(0.0f, 1.0f, 1.0f);
               else if (x == 1) glColor3f(0.0f, 1.0f, 0.0f);
               else if (x == 2) glColor3f(1.0f, 0.0f, 0.0f);
               //___________________________________________
               for (int z = 0; z < 3; z++)
               {
                    glVertex3f((GLfloat)x, 0.0f, (GLfloat)z);
                    glVertex3f((x+1.0f), 0.0, (GLfloat)z);
                    glVertex3f((GLfloat)x, 0.0f, (z+1.0f));
                    glVertex3f((x+1.0f), 0.0f, (z+1.0f));
               }
               glEnd();
          }
     glPopMatrix();

     return true; // return false to stop
}


© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home